/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mscs.server.globalManager.logic;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import mscs.data.IFileDataStore;
import mscs.data.IGoodsProxy;
import mscs.data.pojo.Goods;

/**
 *
 * @author Administrator
 */
public class DeleteGoodsInfoUtil implements IDeleteGoodsInfoUtil{
    private ArrayList<Goods> delList = new ArrayList<Goods> ();
    private IFileDataStore fds = new IGoodsProxy();
    private ArrayList<Goods> allList ;
    
    public DeleteGoodsInfoUtil(){
        allList = (ArrayList<Goods>) fds.getObjects();
    }

    public void addToDelList(Goods goods) {
        delList.add(goods);
    }

    public void removeFromDelList(int index) {
        delList.remove(index);
    }

    public boolean commitDelList() {
        for(Goods goods: delList){
            for(int i=0; i<allList.size(); i++){
                if(goods.getId().equals(allList.get(i).getId())){
                    allList.remove(i);
                }
            }
        }
        fds.update(allList);
        delList = new ArrayList<Goods>();
        return true;
    }

    public List<Goods> getDelList() {
        return this.delList;
    }

    public Goods getByIndex(int index) {
        return this.delList.get(index);
    }
    
}
